package day2;

import org.junit.Test;

public class WhileIfTest {
    @Test
    public void tes1() {
        // System.out.println("HelloWorld");
        /*循环的三要素：
        1、循环条件的初始化
        2、循环条件的控制
        3、循环条件的改变*/
        int count = 1;
        while (count <= 5) {
            System.out.println("HelloWorld");
            count++;
        }
    }

    // 1+2+3+... + 100=5050
    @Test
    public void test2() {
        int i = 1;
        int sum = 0;
        while (i <= 100) {
            System.out.println(i);
            sum = sum + i;// sum += i;
            System.out.println("sum: " + sum);
            i++;
        }
    }

    @Test
    public void test3() {
        // i,j,k
        for (int i = 1; i <= 5; i++) {
            System.out.println("HelloWorld");
        }
    }

    @Test
    public void test4() {
        int sum = 0;
        for (int i = 1; i <= 100; i++) {
            sum += i;
        }
        System.out.println("sum: " + sum);
    }

    // 统计思想，数一下符合条件的有多少个（计算1-100以内7的倍数的个数）
    @Test
    public void test5() {
        int i = 1;
        int count = 0;
        while (i <= 100) {
            if (i % 7 == 0) {
                System.out.println(i);
                count++;
            }
            i++;
        }
        System.out.println("count: " + count);
    }

    @Test
    public void test8() {
        int count = 0;
        for (int i = 1; i <= 100; i++) {
            if (i % 7 == 0) {
                count++;
            }
        }
        System.out.println("count: " + count);
    }


}
